package cn.cloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2017/6/29.
 */
@RestController
@RefreshScope
public class TestController {
    @Autowired
    RestTemplate restTemplate;

    @Value("${ip}")
    private String ip;
    @Value("${port}")
    private String port;



    @RequestMapping("/hi")
    @HystrixCommand(fallbackMethod = "error")
    public String hi(@RequestParam String id){
        return restTemplate.getForObject("http://service-a/hi?id="+id, String.class);
    }

    public String  error(String id){
        return "hi, " + id + ", error!";
    }


    @RequestMapping("/getProperties")
    public String getProperties(){
        return ip + " : " + port;
    }
}
